/**
 * 定义数据维护模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.dataMaintain.dataMaintainManager', ['water.entity.dataMaintain']);
		
	module.controller('dataMaintainManagerController',function($scope,$dataMaintainService){
		$scope.model = {};
		$scope.downLoadSiteCode;
		$scope.logDataPath;

		$scope.onDownloadClick = function(){
            $.messager.confirm("确认","下载配置后，将会覆盖当前配置，确认覆盖？",function(r) {
                if (r) {
                    $dataMaintainService.downloadConfig($scope.downLoadSiteCode).then(function(){
                        alert("下载配置成功，请重启软件");
                    });
                }
            });
		};
		
		$scope.onUploadClick = function(model){
            $dataMaintainService.uploadConfig(model.SITE_CODE).then(function(data){
				alert("上传配置成功");
			},function(data){
				alert(data);
			});
		};
		
		$scope.getModel = function(){
            $dataMaintainService.getModel().then(function(data){
				if(data == null){
					return;
				}
				$scope.model = data[0];
			});
		}
		
		$scope.onSaveClick = function(model){
			model.ID = "01";
            $dataMaintainService.saveModel(model).then(function(data){
				alert("保存成功");
			},function(data){
				alert(data);
			});
		}

		$scope.onReadLogDataClick = function(){
            $.messager.confirm("确认","将删除数据日志记录的时间范围内数据，再根据数据日志进行录入，确认执行？",function(r) {
                if (r) {
                    $dataMaintainService.readLogData($scope.logDataPath).then(function(data){
                        alert("读取日志数据成功");
                    },function(data){
                        alert(data);
                    });
                }
            });
		}
		
		$scope.getModel();
	});
	
}(window, angular));





